//
//  DiscoveryViewController.m
//  GoTraveling
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "DiscoveryViewController.h"
#import "CJSNavigationView.h"
#import "SelectViewController.h"
#import "HotViewViewController.h"

@interface DiscoveryViewController ()<CJSNavigationViewDelegate,UIScrollViewDelegate>

@property (nonatomic, retain) CJSNavigationView *navigationV;
@property (nonatomic, retain) UIScrollView *scrollView;

@property (nonatomic, retain) SelectViewController *selectVC;

@property (nonatomic, retain) NSMutableArray *fourArray;

@property (nonatomic, retain) HotViewViewController *hotVC;

@end

@implementation DiscoveryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    //设置导航栏
    self.navigationV = [[CJSNavigationView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4, 0, SCREEN_WIDTH / 2, 44)];
    self.navigationV.delegate = self;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.18 green:0.21 blue:0.24 alpha:1];
    [self.navigationController.navigationBar addSubview:self.navigationV];
    
    //精选页
    self.selectVC = [[SelectViewController alloc] init];
    [self addChildViewController:self.selectVC];
    
    //热门
    self.hotVC = [[HotViewViewController alloc] init];
    [self addChildViewController:self.hotVC];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SearchBarButton"] style:UIBarButtonItemStylePlain target:self action:@selector(barRAction:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-guanyuwo"] style:UIBarButtonItemStylePlain target:self action:@selector(barLAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    [self scrollview];

}

- (void)barRAction:(UIBarButtonItem *)bar {
    
    
}

- (void)barLAction:(UIBarButtonItem *)bar {
    
    

}

#pragma mark - 主滚动视图
- (void)scrollview {
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49)];
    self.scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 2, self.view.frame.size.height - 49);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    self.scrollView.delegate = self;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.contentOffset = CGPointMake(0, 0);
    [self.view addSubview:self.scrollView];
    
    [self.scrollView addSubview:self.selectVC.view];
    UIView *aview = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.scrollView addSubview:aview];
    [aview addSubview:self.hotVC.view];
    
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    self.navigationV.selectNum = (NSInteger)(scrollView.contentOffset.x / scrollView.frame.size.width);
}

- (void)changeScrollOffset:(NSInteger)selectNum {
    
    [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width * selectNum, 0) animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
